﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;

namespace sistemaAcademicoSalaDeEstudo
{
    public partial class List : System.Web.UI.Page
    {
        protected MetaTable table;

        protected void Page_Init(object sender, EventArgs e)
        {
            DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            table = GridDataSource.GetTable();
            Title = table.DisplayName;

            //InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert);

            // Disable various options if the table is readonly
            if (table.IsReadOnly)
            {
                GridView1.Columns[0].Visible = false;
                //InsertHyperLink.Visible = false;
            }

            DynamicFilterForm1.Focus();
            GridView1.Sort("nomeAluno", SortDirection.Ascending);
            
        }

        protected void OnFilterSelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.PageIndex = 0;
        }


        protected void RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                sistemaAcademicoFinanceiroEscolas.aluno dc = (sistemaAcademicoFinanceiroEscolas.aluno)e.Row.DataItem;

                string codigoAluno = dc.codigoAluno.ToString();

                //se arquivo existe mostra
                
                string caminho =  HttpContext.Current.Server.MapPath( codigoAluno + ".jpg");

                string literal = "<a href=# onclick=javascript:window.open('" + ConfigurationManager.AppSettings["url"] + "/definirImagem.aspx?codigoAluno=" + codigoAluno + "','Aluno','location=0,resizable=0,status=0,scrollbars=0,width=610,height=510');>";
                literal = literal + "<img src=" + ConfigurationManager.AppSettings["url"] + "/imagesAluno/" + codigoAluno + ".jpg" + " title=Clique&nbsp;para&nbsp;modificar&nbsp;a&nbsp;imagem&nbsp;do&nbsp;Aluno border=0 width=50 hight=50></a>";

                caminho = caminho.Replace("alunos", "imagesAluno");

                if (System.IO.File.Exists(caminho))
                {                          
                         
                    e.Row.Cells[0].Controls.Add(new LiteralControl(literal));
                            
                } 
                            
 

            }
        }
    }
}
